<?php

namespace App\services;

use Firebase\JWT\JWT;
use Firebase\JWT\Key;


class JwtService{


    /*
     * 生成 token
     */
    public function encode($data,$expire=7200){

        $key = 'example_key';
        $payload = [

            'id'=>$data['id'],
            'expire'=>time()+$expire
        ];


        $jwt = JWT::encode($payload, $key, 'HS256');

        return $jwt;
    }


    public function decode($jwt)
    {
        $key = 'example_key';
        $decoded = JWT::decode($jwt, new Key($key, 'HS256'));

        return (array) $decoded;
    }
}
